<?php

namespace App\Http\Models\Dances;

use Illuminate\Database\Eloquent\Model;

class Dances extends Model
{
    /**
     * 表名
     * @var string
     */
    protected $table = 'dances';

    /**
     * 不能被赋值的字段
     * @var array
     */
    protected $guarded = ['id'];

    /**
     * 设置输出时字段类型
     * @var array
     */
    protected $casts = [
        'begin_time' => 'timestamp',
        'end_time'   => 'timestamp'
    ];

    /**
     * 设置显示字段
     * @var array
     */
    protected $visible = [
        'id',
        'name',
        'dance_names',
        'teacher_id',
        'begin_time',
        'end_time',
        'course_price',
        'vip_price',
        'address',
        'contents',
        'status',
        'types',
        'remark',
        'images',
        'created_at',
        'updated_at'
    ];

    public function getUserBelongsTo()
    {
        return $this->belongsTo('App\Http\Models\User\User', 'teacher_id', 'id');
    }

    //获取课程
    public function getDances($where)
    {
        return self::query()->where($where)->orderBy('created_at','desc')->get();
    }
    //获取没有过期课程
    public function getDatesTime($where){
       return self::query()->where($where)->where('end_time','>=', strtotime(date('Y-m-d 00:00:00',time())))->orderBy('created_at','desc')->get();
    }
}
